#
# @lc app=leetcode.cn id=350 lang=python3
#
# [350] 两个数组的交集 II
#
from typing import List
from typing import Counter
# @lc code=start
class Solution:
    def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
        d = Counter(nums1)
        arr = []
        for num in nums2:
            if d[num] > 0:
                d[num] = d[num] - 1
                arr.append(num)
        return arr
# @lc code=end

